﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.IO;
using BPM.ReportDesigner.AjaxPage;

namespace BPM.ReportDesigner.GenerateReportFiles
{
    public partial class Template_20130814090636 : System.Web.UI.Page
    {
        private string UserName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            UserName = new GetUserInfo().tttt();
            if (!IsPostBack)
            {
                BingData();
            }
        }

        public void BingData()
        {
             string strWhere = ""; 
 
 
string sql="select PROC_PERSONREIMBURSEMENT.FORMID AS FORMID,PROC_PERSONREIMBURSEMENT.PROCESSNAME AS PROCESSNAME,PROC_PERSONREIMBURSEMENT.INCIDENT AS INCIDENT,PROC_PERSONREIMBURSEMENT.DOCUMENTNO AS DOCUMENTNO,PROC_PERSONREIMBURSEMENT.APPLICANT AS APPLICANT,PROC_PERSONREIMBURSEMENT.REQUESTDATE AS REQUESTDATE,PROC_PERSONREIMBURSEMENT.DEPARTMENT AS DEPARTMENT,PROC_PERSONREIMBURSEMENT.COMPANY AS COMPANY,PROC_PERSONREIMBURSEMENT.PROCESSSUMMARY AS PROCESSSUMMARY,PROC_PERSONREIMBURSEMENT.STATUS AS STATUS,PROC_PERSONREIMBURSEMENT.SSXM AS SSXM,PROC_PERSONREIMBURSEMENT.BH AS BH,PROC_PERSONREIMBURSEMENT.BXJE AS BXJE,PROC_PERSONREIMBURSEMENT.BXJEDX AS BXJEDX,PROC_PERSONREIMBURSEMENT.ZHM AS ZHM,PROC_PERSONREIMBURSEMENT.KHH AS KHH,PROC_PERSONREIMBURSEMENT.YHKH AS YHKH,PROC_PERSONREIMBURSEMENT.WCQKGS AS WCQKGS FROM PROC_PERSONREIMBURSEMENT where 1=1  "+strWhere+"  order by PROC_PERSONREIMBURSEMENT.FORMID ASC"; 
DataSet ds = ExecuteNonQuery(sql); 
ReportList.DataSource = ds; 
ReportList.DataBind(); 

        }

        

        

        protected void ExportToExcel_Click(object sender, EventArgs e)
        {
            string strWhere = ""; 
 
DataTable tb = ExecuteNonQuery("select PROC_PERSONREIMBURSEMENT.FORMID AS FORMID,PROC_PERSONREIMBURSEMENT.PROCESSNAME AS PROCESSNAME,PROC_PERSONREIMBURSEMENT.INCIDENT AS INCIDENT,PROC_PERSONREIMBURSEMENT.DOCUMENTNO AS DOCUMENTNO,PROC_PERSONREIMBURSEMENT.APPLICANT AS APPLICANT,PROC_PERSONREIMBURSEMENT.REQUESTDATE AS REQUESTDATE,PROC_PERSONREIMBURSEMENT.DEPARTMENT AS DEPARTMENT,PROC_PERSONREIMBURSEMENT.COMPANY AS COMPANY,PROC_PERSONREIMBURSEMENT.PROCESSSUMMARY AS PROCESSSUMMARY,PROC_PERSONREIMBURSEMENT.STATUS AS STATUS,PROC_PERSONREIMBURSEMENT.SSXM AS SSXM,PROC_PERSONREIMBURSEMENT.BH AS BH,PROC_PERSONREIMBURSEMENT.BXJE AS BXJE,PROC_PERSONREIMBURSEMENT.BXJEDX AS BXJEDX,PROC_PERSONREIMBURSEMENT.ZHM AS ZHM,PROC_PERSONREIMBURSEMENT.KHH AS KHH,PROC_PERSONREIMBURSEMENT.YHKH AS YHKH,PROC_PERSONREIMBURSEMENT.WCQKGS AS WCQKGS FROM PROC_PERSONREIMBURSEMENT WHERE 1=1  "+strWhere+"  order by PROC_PERSONREIMBURSEMENT.FORMID ASC").Tables[0]; 
Response.Clear(); 
Response.Charset = "GB2312"; 
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); 
Response.ContentType = "application/ms-excel"; 
Response.AppendHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DateTime.Now.ToShortDateString(), System.Text.Encoding.GetEncoding("GB2312")) + ".xls"); 
CultureInfo cult = new CultureInfo("zh-CN", true); 
StringWriter sw = new StringWriter(cult); 
HtmlTextWriter htw = new HtmlTextWriter(sw); 
DataGrid dgrid = new DataGrid(); 
dgrid.DataSource = tb.DefaultView; 
dgrid.AllowPaging = false; 
dgrid.DataBind(); 
htw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=GB2312\">"); 
dgrid.RenderControl(htw); 
Response.Write(sw.ToString()); 
Response.End(); 

        }

        public DataSet ExecuteNonQuery(string sql) 
{ 
     using(OleDbConnection oleConn=new OleDbConnection("Provider=SQLOLEDB.1;User ID=sa;Password=sa;Initial Catalog=UltimusBusiness;Data Source=.")) 
     { 
         using (OleDbCommand cmd = new OleDbCommand(sql, oleConn)) 
         { 
             using (OleDbDataAdapter oda = new OleDbDataAdapter(cmd)) 
             { 
                 DataSet ds = new DataSet(); 
                 oda.Fill(ds); 
                 return ds; 
             } 
         } 
     } 
} 


    }
}